import urllib.request


"""
    直接获取  个人中心页面
    手动黏贴 复制到 PC 抓包的cookie
    放在请求头里面
"""

url = 'https://www.douban.com/'
# 请求头
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
    'Cookie':'douban-fav-remind=1; viewed="21559381_20435400_1052990_1068920_24271668_24375031"; gr_user_id=a45eeee8-f568-4ee2-967f-9969f4ed728b; bid=nCvGJrlIMXw; __yadk_uid=0vLBVU8PCzMjNPHfoirLP8wnZkT5VMom; ll="118216"; dbcl2="202174839:vJMgxG38Z5Y"; ps=y; _vwo_uuid_v2=DB62E50E5D10CDEBBA710CAD00A95782E|baf6f59c1178fdbced45ee1bfcd9a18c; ck=P-Md; ap_v=0,6.0; _pk_ref.100001.8cb4=%5B%22%22%2C%22%22%2C1566639090%2C%22https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DrzAgZfD72wIwfNKAQggqRFgEaRdvQqjG5Xlkwu69789NKNC3yM2YoaZN1VGDEOoB%26wd%3D%26eqid%3Dce6261aa0003fd31000000025d6103ec%22%5D; push_noty_num=0; push_doumail_num=0; __utmt=1; __utma=30149280.1030948902.1561890023.1566041745.1566639091.6; __utmb=30149280.3.9.1566639091; __utmc=30149280; __utmz=30149280.1566639091.6.6.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; __utmv=30149280.20217; _pk_id.100001.8cb4=3469673770fabf92.1538055810.25.1566639187.1563348252.; _pk_ses.100001.8cb4=*'
}
# 构建请求对象
request = urllib.request.Request(url,headers=headers)
# 发送请求对象  获取响应对象
response = urllib.request.urlopen(request)

data = response.read().decode('utf-8');
# data = str(response.read())
print(type(data))

# 保存到文件
with open('01cookie.html', 'w', encoding='utf-8') as f:
    f.write(data)

